package com.my.study.springframework.test.proxy.jdk;

import java.io.Serializable;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * 人的代理类
 *
 * @author: yidujun
 * @create: 2021/07/13 14:25
 */
@SuppressWarnings("serial")
public class PersonProxy implements InvocationHandler, Serializable {
    private Person targetPerson;

    public PersonProxy(Person targetPerson) {
        this.targetPerson = targetPerson;
    }

    /**
     * 目标对象和代理对象进行绑定...
     *
     * @return
     */
    public Person bind() {
        return (Person) Proxy.newProxyInstance(targetPerson.getClass().getClassLoader(), targetPerson.getClass().getInterfaces(), this);
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("愿世间没有996，没有007");
        method.invoke(targetPerson, args);
        return null;
    }
}
